var Beamr = Beamr || { 'settings': {}, 'behaviors': {}, 'locale': {} };

/**
 * Set the variable that indicates if JavaScript behaviors should be applied
 */
Beamr.jsEnabled = document.getElementsByTagName && document.createElement && document.createTextNode && document.documentElement && document.getElementById;

/**
 * Attach all registered behaviors to a page element.
 *
 * Behaviors are event-triggered actions that attach to page elements, enhancing
 * default non-Javascript UIs. Behaviors are registered in the Beamr.behaviors
 * object as follows:
 * @code
 *    Beamr.behaviors.behaviorName = function () {
 *      ...
 *    };
 * @endcode
 *
 * Beamr.attachBehaviors is added below to the jQuery ready event and so
 * runs on initial page load. Developers implementing AHAH/AJAX in their
 * solutions should also call this function after new page content has been
 * loaded, feeding in an element to be processed, in order to attach all
 * behaviors to the new content.
 *
 * Behaviors should use a class in the form behaviorName-processed to ensure
 * the behavior is attached only once to a given element. (Doing so enables
 * the reprocessing of given elements, which may be needed on occasion despite
 * the ability to limit behavior attachment to a particular element.)
 *
 * @param context
 *   An element to attach behaviors to. If none is given, the document element
 *   is used.
 */
Beamr.attachBehaviors = function(context) {
  context = context || document;
  if (Beamr.jsEnabled) {
    // Execute all of them.
    jQuery.each(Beamr.behaviors, function() {
      this(context);
    });
  }
};

// Global Killswitch on the <html> element
if (Beamr.jsEnabled) {
  // Global Killswitch on the <html> element
  $(document.documentElement).addClass('js');
  // 'js enabled' cookie
  document.cookie = 'has_js=1; path=/';
  // Attach all behaviors.
  $(document).ready(function() {
    Beamr.attachBehaviors(this);
  });
}